define(function(){
	var handlerServiceRadius,handlerDis, handlerArea, handlerHeight,thislayer, handlerShadow, shadowQuery, handlerLimitBody, handlerViewPoint, sightline, pointHandler, viewshed3D, slope, wide, handlerPolygon,pointHandler_areaView,handlerPoint,handlerPolygon1,handlerPolygon2;
	var viewModel,handler,toolbar,handler2,handlerLineProfileAnalysis,handlerPolygonSlope;
	var currentHeight = 0;
    var maxValue = 0;
    var minValue = 0;
    var int = null;
	//函数：获取尺寸
	function _autodivheight() { 
		//获取浏览器窗口高度
		var winHeight = 0;
		if (window.innerHeight) winHeight = window.innerHeight;
		else if ((document.body) && (document.body.clientHeight)) winHeight = document.body.clientHeight;
		//通过深入Document内部对body进行检测，获取浏览器窗口高度
		if (document.documentElement && document.documentElement.clientHeight) winHeight = document.documentElement.clientHeight;
		//DIV高度为浏览器窗口的高度
		//document.getElementById("test").style.height= winHeight +"px";
		//DIV高度为浏览器窗口高度的一半
		if (document.getElementById("content")) document.getElementById("content").style.height = (winHeight - 100) + "px";
		if (document.getElementById("left")) document.getElementById("left").style.height = (winHeight - 100) + "px";
		if (document.getElementById("right")) document.getElementById("right").style.height = (winHeight - 100) + "px";		
		if (document.getElementById("mapDiv")) document.getElementById("mapDiv").style.height = (winHeight - 132) + "px";
	}

//淹没分析
 //点击“开始”按钮，则开始淹没分析
            document.getElementById("begin").onclick = function() {
            	
            	//关闭其他所有图层
            	_hiddenAllLayers();

                flood_currentHeight = 0;
                flood_int = self.setInterval("flood()", 100);
                flood_maxValue = parseInt(document.getElementById("maxHeight").value);
                flood_minValue = parseInt(document.getElementById("minHeight").value);
            };

            window.flood = function() {

                if(flood_currentHeight > flood_maxValue) {
                    self.clearInterval(flood_int);
                    //alert("4");
                    return;
                }

                var layer = scene.layers.find("倾斜摄影淹没分析");
                var hyp = new Cesium.HypsometricSetting();
                //创建分层设色对象   设置最大/最小可见高度   颜色表  显示模式   透明度及线宽
                var colorTable = new Cesium.ColorTable();

                hyp.MaxVisibleValue = flood_currentHeight;
                hyp.MinVisibleValue = flood_minValue;

                // var value = $("#colorTable").find("option:selected")[0].value;
                // setColorTable(colorTable, value);

                colorTable.insert(71, new Cesium.Color(210/255, 15/255, 15/255));
                colorTable.insert(54, new Cesium.Color(221/255, 224/255, 7/255));
                colorTable.insert(36, new Cesium.Color(20/255, 187/255, 18/255));
                colorTable.insert(18, new Cesium.Color(0, 161/255, 1));
                colorTable.insert(0, new Cesium.Color(9/255, 9/255, 212/255));

                hyp.ColorTable = colorTable;
                hyp.DisplayMode = Cesium.HypsometricSettingEnum.DisplayMode.FACE;
                hyp.Opacity = 0.5;

                hyp.LineInterval = 10.0;

                //设置图层分层设色属性
                layer.hypsometricSetting = {
                    hypsometricSetting : hyp,
                    analysisMode : Cesium.HypsometricSettingEnum.AnalysisRegionMode.ARM_ALL
                };

                flood_currentHeight += (parseInt(document.getElementById("speed").value))/10;

            };

            //清除分析结果
            document.getElementById("clear").onclick = function() {
				

                self.clearInterval(flood_int);
                var layer = scene.layers.find("倾斜摄影淹没分析");
                var hyp = new Cesium.HypsometricSetting();
                hyp.MaxVisibleValue = 0;

                layer.hypsometricSetting = {
                    hypsometricSetting : hyp,
                    analysisMode : Cesium.HypsometricSettingEnum.AnalysisRegionMode.ARM_ALL
                }

                //显示其他图层
				_showAllLayers();
            };


		//关闭地球上所有图层
		 function _hiddenAllLayers () {

		        $.each(GlobalAllLayers,function(i, v) {

						if (v instanceof Cesium.S3MTilesLayer) {
							
							GlobalAllLayers[i].style3D.fillForeColor.alpha = parseFloat(0);
					    }

					    else if(v instanceof Cesium.ImageryLayer){
					    	GlobalAllLayers[i].show = false;
					    }

					});
				var promise =  scene.addS3MTilesLayerByScp('http://172.29.1.26:8090/iserver/services/3D-py057/rest/realspace/datas/%E5%80%BE%E6%96%9C%E6%91%84%E5%BD%B1/config',{name : '倾斜摄影淹没分析'});
		        
		    }
    
		//显示地球上所有图层
		 function _showAllLayers() {

			 $.each(GlobalAllLayers,function(i, v) {

			 		 var layer = scene.layers.find("倾斜摄影淹没分析");
					layer.style3D.fillForeColor.alpha = parseFloat(0);

			        if (v instanceof Cesium.S3MTilesLayer) {
			        	GlobalAllLayers[i].style3D.fillForeColor.alpha = parseFloat(1);
					}
					else if(v instanceof Cesium.ImageryLayer){
						GlobalAllLayers[i].show = true;
					}
			});

		  }

		  //七线控制
		  function _sevenLineAnalysis(){
		  		
		  		var layer = scene.layers.find("红线@C");
		  		layer.style3D.fillForeColor.alpha = parseFloat(1);
		  }
		  //清除七线控制
		  function _clearSevenLineAnalysis(){
		  		
		  		var layer = scene.layers.find("红线@C");
		  		layer.style3D.fillForeColor.alpha = parseFloat(0);
		  }

		  //控高分析
		  function _controlHeightAnalysis(){

		  		
		  		var layer = scene.layers.find("控高分析@konggui");
		  		layer.style3D.fillForeColor.alpha = parseFloat(1);
		  }
		  //清除控高分析
		  function _clearControlHeightAnalysis(){
		  		
		  		var layer = scene.layers.find("控高分析@konggui");
		  		layer.style3D.fillForeColor.alpha = parseFloat(0);
		  }


		  //剖面分析
		  function _profileAnalysis(){

		  
		  	//划线
		  	var profile = new Cesium.Profile(scene);
		  	 handlerLineProfileAnalysis = new Cesium.DrawHandler(viewer,Cesium.DrawMode.Line);
            handlerLineProfileAnalysis.activate();
				handlerLineProfileAnalysis.drawEvt.addEventListener(function(result) { 
                //tooltip.setVisible(false);
                var line=result.object;
                var startPoint = line._positions[0];
                var endPoint = line._positions[line._positions.length - 1];

                var scartographic = Cesium.Cartographic.fromCartesian(startPoint);
                var slongitude = Cesium.Math.toDegrees(scartographic.longitude);
                var slatitude = Cesium.Math.toDegrees(scartographic.latitude);
                var sheight = scartographic.height;

                var ecartographic = Cesium.Cartographic.fromCartesian(endPoint);
                var elongitude = Cesium.Math.toDegrees(ecartographic.longitude);
                var elatitude = Cesium.Math.toDegrees(ecartographic.latitude);
                var eheight = ecartographic.height;

                //设置坡面分析的开始和结束位置
                profile.startPoint = [slongitude, slatitude, sheight];
                profile.endPoint = [elongitude, elatitude, eheight];

                profile.extendHeight = 40;

                //分析完毕的回调函数
                profile.getBuffer(function(buffer) {
                    
                    var canvas = document.getElementById("pro");
                    canvas.height = profile._textureHeight;
                    canvas.width = profile._textureWidth;
                    var ctx = canvas.getContext("2d");
                    var imgData = ctx.createImageData(profile._textureWidth, profile._textureHeight);
                    imgData.data.set(buffer);
                    //在canvas上绘制图片
                    ctx.putImageData(imgData,0,0);
                    $("#pro").width(600);
                    $("#pro").height(450);
                });

                profile.build();
            });
		  }

		  //清除剖面分析
		  function _clearProfileAnalysis(){

		 
		  	 handlerLineProfileAnalysis.clear();
		  	handlerLineProfileAnalysis.deactivate();
                $("#pro").width(0);
                $("#pro").height(0);
		  }

		    //方案比选
		 function _HORIZONTAL() {
		 		
		        scene.multiViewportMode = Cesium.MultiViewportMode["HORIZONTAL"];
		    }

		    //清除方案比选
		 function _clearHORIZONTAL() {
		 		
		 		scene.multiViewportMode = Cesium.MultiViewportMode["NONE"];
		 }
		 //地形坡度坡向分析
		 function _startSlopeAnalysis(){
		 	
		 	scene.globe.enableLighting = true;
		 	
			 $("#wideminR").on("input change",function(){
	           var a = document.getElementById("widemin");
	            a.value = this.value;
	            slope.MinVisibleValue = this.value;
	            viewer.scene.globe.SlopeSetting = {
	                slopeSetting : slope,
	                analysisMode : wide
	            };
	        });
	        $("#widemin").on("input change",function(){
	            var a = document.getElementById("widemin");
	            a.value = this.value;
	        });
	        $("#widemaxR").on("input change",function(){
	            var a = document.getElementById("widemax");
	            a.value = this.value;
	            slope.MaxVisibleValue = this.value;
	            viewer.scene.globe.SlopeSetting = {
	                slopeSetting : slope,
	                analysisMode : wide
	            };
	        });
	        $("#widemax").on("input change",function(){
	            var a = document.getElementById("widemaxR");
	            a.value = this.value;
	        });


			var slope = new Cesium.SlopeSetting();
	       	slope.DisplayMode = Cesium.SlopeSettingEnum.DisplayMode.FACE_AND_ARROW;
	        slope.MaxVisibleValue = document.getElementById("widemax").value;;
	        slope.MinVisibleValue =  document.getElementById("widemin").value;
	        var colorTable = new Cesium.ColorTable();
	        colorTable.insert(0, new Cesium.Color(255/255, 0/255, 0/255));
	        colorTable.insert(20, new Cesium.Color(221/255, 224/255, 7/255));
	        colorTable.insert(30, new Cesium.Color(20/255, 187/255, 18/255));
	        colorTable.insert(50, new Cesium.Color(0, 161/255, 1));
	        colorTable.insert(80, new Cesium.Color(9/255, 9/255, 255/255));
	        var wide;
	        wide =  Cesium.HypsometricSettingEnum.AnalysisRegionMode.ARM_REGION;
	        slope.ColorTable = colorTable;
	        slope.Opacity = 0.5;

	        //绘制多边形
	        handlerPolygonSlope = new Cesium.DrawHandler(viewer,Cesium.DrawMode.Polygon,0);
			
	        handlerPolygonSlope.drawEvt.addEventListener(function(result){
	        	
	            if(!result.object.positions){

	                handlerPolygonSlope.polygon.show = false;
	                handlerPolygonSlope.polyline.show = false;
	                handlerPolygonSlope.deactivate();
	                handlerPolygonSlope.activate();
	                return;
	            };

				

	            var array = [].concat(result.object.positions);

	            var positions = [];
	            for(var i = 0, len = array.length; i < len; i ++){
	                var cartographic = Cesium.Cartographic.fromCartesian(array[i]);
	                var longitude = Cesium.Math.toDegrees(cartographic.longitude);
	                var latitude = Cesium.Math.toDegrees(cartographic.latitude);
	                var h=cartographic.height;
	                if(positions.indexOf(longitude)==-1&&positions.indexOf(latitude)==-1){
	                    positions.push(longitude);
	                    positions.push(latitude);
	                    positions.push(h);
	                }
	            }

	            slope.CoverageArea = positions;
	            viewer.scene.globe.SlopeSetting = {
	                slopeSetting : slope,
	                analysisMode : wide
	            };
	            handlerPolygonSlope.polygon.show = false;
	            handlerPolygonSlope.polyline.show = true;
	            handlerPolygonSlope.deactivate();
	            handlerPolygonSlope.activate();
            });

	        handlerPolygonSlope.activate();
		 }


		 //清除地形坡度坡向分析
 		function _clearSlopeAnalysis(){
				
  				handlerPolygonSlope.polygon.show = false;
	            handlerPolygonSlope.polyline.show = false;
				handlerPolygonSlope.deactivate();
				viewer.scene.globe.SlopeSetting = {
	                slopeSetting : undefined,
	                analysisMode : undefined
	            };
 		}


		//服务半径分析
		function _serviceRadius() {
		
			handlerViewPoint = new Cesium.PointHandler(viewer);
			handlerViewPoint.drawCompletedEvent.addEventListener(function(point) {
				var position = point.position._value;

				//将获取的点的位置转化成经纬度
				var cartographic = Cesium.Cartographic.fromCartesian(position);
				var height = cartographic.height;

				
					viewer.entities.remove(point);

					//添加视点

					        //在点击位置添加对应点
		        var greenCircle = viewer.entities.add({

			    position: position,

			    name : 'Green circle at height',

			    ellipse : {

			        semiMinorAxis : parseInt(document.getElementById("serviceRadiusValue").value),

			        semiMajorAxis : parseInt(document.getElementById("serviceRadiusValue").value),

			        height: height+20, //浮空

			        material : Cesium.Color.GREEN.withAlpha(0.5)

			    	}

				});
				

			});
			
			handlerViewPoint.activate();
	 		
		}

	function _clearServiceRadius(){
		
		//首先移除之前添加的点
        viewer.entities.removeAll();
       handlerViewPoint.deactivate();
	}

	//标绘
	function _plotting(type){
		var clampMode = 0;
		var handlerPoint = new Cesium.DrawHandler(viewer,Cesium.DrawMode.Point);
		var handlerLine = new Cesium.DrawHandler(viewer,Cesium.DrawMode.Line);
		var handlerPolygon = new Cesium.DrawHandler(viewer,Cesium.DrawMode.Polygon,clampMode);
		var handlerMarker = new Cesium.DrawHandler(viewer,Cesium.DrawMode.Marker);

		if (type!=undefined&&type=='Point') {
			deactiveAll();
			handlerPoint.activate();
			handlerPoint.activeEvt.addEventListener(function(isActive){
				if(isActive == true){
					viewer.enableCursorStyle = false;
					viewer._element.style.cursor = '';
					$('body').removeClass('drawCur').addClass('drawCur');
				}
				else{
					viewer.enableCursorStyle = true;
					$('body').removeClass('drawCur');
				}
			});
		}

		if (type!=undefined&&type=='polyline') {
			deactiveAll();
			handlerLine.activate();
			handlerLine.activeEvt.addEventListener(function(isActive){
				if(isActive == true){
					viewer.enableCursorStyle = false;
					viewer._element.style.cursor = '';
					$('body').removeClass('drawCur').addClass('drawCur');
				}
				else{
					viewer.enableCursorStyle = true;
					$('body').removeClass('drawCur');
				}
			});
		}

		if (type!=undefined&&type=='polygon') {
			deactiveAll();
			handlerPolygon.activate();
			handlerPolygon.activeEvt.addEventListener(function(isActive){
				if(isActive == true){
					viewer.enableCursorStyle = false;
					viewer._element.style.cursor = '';
					$('body').removeClass('drawCur').addClass('drawCur');
				}
				else{
					viewer.enableCursorStyle = true;
					$('body').removeClass('drawCur');
				}
			});
		}

		if (type!=undefined&&type=='marker'){
			deactiveAll();
			handlerMarker.activate();
			handlerMarker.activeEvt.addEventListener(function(isActive){
				if(isActive == true){
					viewer.enableCursorStyle = false;
					viewer._element.style.cursor = '';
					$('body').removeClass('drawCur').addClass('drawCur');
				}
				else{
					viewer.enableCursorStyle = true;
					$('body').removeClass('drawCur');
				}
			});
		}

		if (type!=undefined&&type=='clear'){
			clearAll();
		}

 		function clearAll(){
 			handlerLine.clear();
            handlerPoint.clear();
            handlerPolygon.clear();
            handlerMarker.clear();
 		}

		function deactiveAll(){
			handlerLine.deactivate();
			handlerPoint.deactivate();
			handlerPolygon.deactivate();
			handlerMarker.deactivate();
		}
		
	}

	//测距
	function _distance() {
		_clear();
		handlerDis = new Cesium.MeasureHandler(viewer, Cesium.MeasureMode.Distance, 0);
		handlerDis.measureEvt.addEventListener(function(result) {
			var distance = result.distance > 1000 ? (result.distance / 1000) + 'km': result.distance + 'm';
			handlerDis.disLabel.text = '距离:' + distance;

		});
		handlerDis.activeEvt.addEventListener(function(isActive) {
			if (isActive == true) {
				viewer.enableCursorStyle = false;
				viewer._element.style.cursor = '';
				$('body').removeClass('measureCur').addClass('measureCur');
			} else {
				viewer.enableCursorStyle = true;
				$('body').removeClass('measureCur');
			}
		});
		handlerDis && handlerDis.activate();
	}

	//测面积
	function _area(){
		_clear();
		handlerArea = new Cesium.MeasureHandler(viewer,Cesium.MeasureMode.Area,0);
        handlerArea.measureEvt.addEventListener(function(result){
            var area = result.area > 1000000 ? (result.area/1000000) + 'km²' : result.area + '㎡'
            handlerArea.areaLabel.text = '面积:' + area;
        });
        handlerArea.activeEvt.addEventListener(function(isActive){
            if(isActive == true){
                viewer.enableCursorStyle = false;
                viewer._element.style.cursor = '';
                $('body').removeClass('measureCur').addClass('measureCur');
            }
            else{
                viewer.enableCursorStyle = true;
                $('body').removeClass('measureCur');
            }
        });
		handlerArea && handlerArea.activate();
	}

	//测高
	function _height() {
		_clear();
		handlerHeight = new Cesium.MeasureHandler(viewer, Cesium.MeasureMode.DVH);
		handlerHeight.measureEvt.addEventListener(function(result) {
			var distance = result.distance > 1000 ? (result.distance / 1000) + 'km': result.distance + 'm';
			var vHeight = result.verticalHeight > 1000 ? (result.verticalHeight / 1000) + 'km': result.verticalHeight + 'm';
			var hDistance = result.horizontalDistance > 1000 ? (result.horizontalDistance / 1000) + 'km': result.horizontalDistance + 'm';
			handlerHeight.disLabel.text = '空间距离:' + distance;
			handlerHeight.vLabel.text = '垂直高度:' + vHeight;
			handlerHeight.hLabel.text = '水平距离:' + hDistance;
		});
		handlerHeight.activeEvt.addEventListener(function(isActive) {
			if (isActive == true) {
				viewer.enableCursorStyle = false;
				viewer._element.style.cursor = '';
				$('body').removeClass('measureCur').addClass('measureCur');
			} else {
				viewer.enableCursorStyle = true;
				$('body').removeClass('measureCur');
			}
		});
		handlerHeight && handlerHeight.activate();
	}

	//地表开挖
	function _digTerrain() {
		_clear();
		handlerPolygon = new Cesium.DrawHandler(viewer, Cesium.DrawMode.Polygon, 0);
		handlerPolygon.activeEvt.addEventListener(function(isActive) {
			if (isActive == true) {
				viewer.enableCursorStyle = false;
				viewer._element.style.cursor = '';
				$('body').removeClass('drawCur').addClass('drawCur');
			} else {
				viewer.enableCursorStyle = true;
				$('body').removeClass('drawCur');
			}
		});
		handlerPolygon.drawEvt.addEventListener(function(result) {
			var array = [].concat(result.object.positions);
			var positions = [];
			for (var i = 0,
			len = array.length; i < len; i++) {
				var cartographic = Cesium.Cartographic.fromCartesian(array[i]);
				var longitude = Cesium.Math.toDegrees(cartographic.longitude);
				var latitude = Cesium.Math.toDegrees(cartographic.latitude);
				var h = cartographic.height;
				if (positions.indexOf(longitude) == -1 && positions.indexOf(latitude) == -1) {
					positions.push(longitude);
					positions.push(latitude);
					positions.push(h);
				}
			}
			viewer.scene.globe.removeAllExcavationRegion();
			viewer.scene.globe.addExcavationRegion({
				name: 'ggg',
				position: positions,
				height: 15,
				transparent: false
			});
			handlerPolygon.polygon.show = false;
			handlerPolygon.polyline.show = false;
			handlerPolygon.deactivate();
			handlerPolygon.activate();
		});
		handlerPolygon && handlerPolygon.activate();
	}

	//清除
	function _clear() {
		$("#flyControl").hide();
		// 清除测距
		if (handlerDis) {
			handlerDis.clear();
		}
		// 清除测面
		if (handlerArea) {
			handlerArea.clear();
		}
		// 清除测高
		if (handlerHeight) {
			handlerHeight.clear();
		}
		//清除天际线
		if (skyline) {
			skyline.clear();
		}
		//清除方案比选
		// if (HORIZONTAL) {
		// 	HORIZONTAL.clear();
		// }
		//清理通视分析
		if (sightline) {
			sightline.removeAllTargetPoint();
			sightline.couldRemove = false;
		}
		
		//清除阴影
		if (handlerShadow) {
			viewer.shadows =  true;
			handlerShadow.deactivate();
			handlerShadow.polygon.show = false;
			handlerShadow.polyline.show = false;
			shadowQuery.qureyRegion({
				position: [0, 0],
				bottom: 0,
				extend: 0
			});
			if (scene.layers._layerQueue[0].shadowType == 2) {
				$.each(scene.layers._layerQueue , function(i, v) {
					v.shadowType = 0;
				});
			}
            $("#shadowRadioBox").find("input[type='text']").val("");
			setTimeout(function(){
                viewer.shadows =  false;
			},1000);
		
		}

		//清除添加
		if (handlerPolygon1) {
			// handlerPolygon1.polygon.show = false;
			handlerPolygon1.polyline.show = false;			
		}
		
		
		//清除控告分析
		if(true){
			viewer.dataSources.removeAll();
			Cesium.knockout.cleanNode(setbar_polygon);
			$("#setbar_polygon").find("input[type='range']").val("");
			$("#setbar_polygon").find("input[type='text']").val("");
		}


		// 清除地表开挖
		if (handlerPolygon) {
			handlerPolygon.polyline.show = false;
			viewer.scene.globe.removeAllExcavationRegion();
			handlerPolygon.deactivate();			
			viewer._element.style.cursor = '';
		}


		//清除坡度坡向
		if (slope) {
			viewer.scene.globe.SlopeSetting = {
				slopeSetting: slope,
				analysisMode: Cesium.HypsometricSettingEnum.AnalysisRegionMode.ARM_NONE
			};

			handlerPolygon.polygon.show = false;
			handlerPolygon.polyline.show = false;
			handlerPolygon.deactivate();

		}

		//清除视域分析
		if (pointHandler_areaView) {
			if(pointHandler_areaView.active) {
				return;
			}
			//先清除之前的可视域分析
			pointHandler_areaView.deactivate();            
			scene.viewFlag = true;
			Cesium.knockout.cleanNode(toolbar);
			viewshed3D._update = false;
			viewer.entities.removeAll();
			viewshed3D.destroy();
			handler && handler.destroy(); 
			$("#wrapper").find("input[type='range']").val("");
			$("#wrapper").find("input[type='text']").val("");			
			return false;
		}
		
        //清除添加的模型
		if (handlerPoint) {
			handlerPoint.deactivate();
			Cesium.knockout.cleanNode(toolbar);
			if(viewer.selectedEntity){
                var instance = viewer.selectedEntity.primitive;
				var index = viewer.selectedEntity.index;
                instance.updateScale(new Cesium.Cartesian3(0,0,0),index);
            }
			$('#loadingbar').remove();
			$("#addModelSetting").hide();
		}

		viewer.entities.removeAll();
	}

	//飞行 环视
	function _huanshi() {
		$("#flyControl").show();
		var routes = new Cesium.RouteCollection();
		var fpfUrl = publicDir + "/fly/landing.fpf";
		routes.fromFile(fpfUrl);
		flyManager = new Cesium.FlyManager({
			scene: scene,
			routes: routes
		});
		if (flyManager.readyPromise) {
			Cesium.when(flyManager.readyPromise,
			function() {
				flyManager.play();
			})
		}
	}

	

	//阴影分析
	function _shadowAnalysis() {
		//_clear();
		//清除
		if(shadowQuery){
			shadowQuery.qureyRegion({
				position: [0, 0],
				bottom: 0,
				extend: 0
			});
		}
		//
		viewer.shadows = true;
		shadowQuery = new Cesium.ShadowQueryPoints(scene);
		$.each(scene.layers._layerQueue,
		function(i, v) {
			v.shadowType = 2;
		});
		shadowQuery.build();
		handlerShadow = new Cesium.DrawHandler(viewer, Cesium.DrawMode.Polygon, 0);
		handlerShadow.activeEvt.addEventListener(function(isActive) {
			if (isActive == true) {
				viewer.enableCursorStyle = false;
				viewer._element.style.cursor = '';
				$('body').removeClass('drawCur').addClass('drawCur');
			} else {
				viewer.enableCursorStyle = true;
				$('body').removeClass('drawCur');
			}
		});
		var points = [];
		handlerShadow.drawEvt.addEventListener(function(result) {
			var polygon = result.object;
			if (!polygon) {
				return;
			}
			polygon.show = false;
			handlerShadow.polyline.show = false;
			var positions = [].concat(polygon.positions);
			positions = Cesium.arrayRemoveDuplicates(positions, Cesium.Cartesian3.equalsEpsilon);
			for (var i = 0,
			len = positions.length; i < len; i++) {
				//转化为经纬度，并加入至临时数组
				var cartographic = Cesium.Cartographic.fromCartesian(polygon.positions[i]);
				var longitude = Cesium.Math.toDegrees(cartographic.longitude);
				var latitude = Cesium.Math.toDegrees(cartographic.latitude);
				points.push(longitude);
				points.push(latitude);
			}
			//设置分析对象的开始结束时间
			var dateValue = $("#selDate").val();
			var startTime = new Date(dateValue);
			startTime.setHours(Number($("#startTime").val()));
			shadowQuery.startTime = Cesium.JulianDate.fromDate(startTime);

			var endTime = new Date(dateValue);
			endTime.setHours(Number($("#endTime").val()));
			shadowQuery.endTime = Cesium.JulianDate.fromDate(endTime);

			shadowQuery.spacing = 10;
			shadowQuery.timeInterval = 60;

			//设置分析区域、底部高程和拉伸高度
			var bh = Number($('#bottomHeight').val());
			var eh = Number($('#extrudeHeight').val());
			shadowQuery.qureyRegion({
				position: points,
				bottom: bh,
				extend: eh
			});
		});
		handlerShadow.deactivate();
		handlerShadow.activate();
	}

	//获取阴影率
	function _shadowRadio() {
		$('#shadowRadioText').val('');
		$('#longitudeText').val('');
		$('#latitudeText').val('');
		$('#heightText').val('');

		handler = new Cesium.ScreenSpaceEventHandler(scene.canvas);
		handler.setInputAction(function(e) {
			var position1 = scene.pickPosition(e.position);
			var cartographic = Cesium.Cartographic.fromCartesian(position1);
			var shadowRadio = shadowQuery.getShadowRadio(cartographic);
			var longitude = Cesium.Math.toDegrees(cartographic.longitude);
			var latitude = Cesium.Math.toDegrees(cartographic.latitude);
			var height = cartographic.height;
			viewer.entities.removeAll();

			if (shadowRadio != -1) {
				$('#shadowRadioText').val(shadowRadio);
				$('#longitudeText').val(longitude);
				$('#latitudeText').val(latitude);
				$('#heightText').val(height);
				viewer.entities.add(new Cesium.Entity({
					point: new Cesium.PointGraphics({
						color: new Cesium.Color(1, 0, 0, 0.5),
						pixelSize: 15

					}),
					position: Cesium.Cartesian3.fromDegrees(longitude, latitude, height)
				}));
			} else {
				$('#shadowRadioText').val('');
				$('#longitudeText').val('');
				$('#latitudeText').val('');
				$('#heightText').val('');
			}
		},
		Cesium.ScreenSpaceEventType.LEFT_CLICK);
	}

	//提取天际线
	function _chooseSkyline() {
		// _clear();
		
		var cartographic = scene.camera.positionCartographic;
		var longitude = Cesium.Math.toDegrees(cartographic.longitude);
		var latitude = Cesium.Math.toDegrees(cartographic.latitude);
		var height = cartographic.height;

		//天际线分析的视口位置设置成当前相机位置
		
		skyline.viewPosition = [longitude, latitude, height];

		//设置俯仰和方向
		skyline.pitch = Cesium.Math.toDegrees(scene.camera.pitch);
		skyline.direction = Cesium.Math.toDegrees(scene.camera.heading);
		skyline.radius = 10000; // 天际线分析半径设置为10000米

		//alert("经度："+longitude+"纬度："+latitude+"高度："+height+"skyline.pitch"+skyline.pitch+"skyline.direction"+skyline.direction);


		skyline.build();
	}

	//绘制限高体
	function _setLimitBody() {
		var unique = function(arr) {
			var res = [];
			var json = {};
			for (var i = 0; i < arr.length; i++) {
				if (!json[arr[i]]) {
					res.push(arr[i]);
					json[arr[i]] = 1;
				}
			}
			return res;
		}
		handlerLimitBody = new Cesium.PolygonHandler(viewer);
		handlerLimitBody.drawCompletedEvent.addEventListener(function(polygon) {
			handlerLimitBody.currentDrawingPolygon.show = false;
			skyline.removeLimitbody("limitBody");
			var positions = [];
			//遍历多边形，取出所有点
			for (var i = 0,
			len = polygon.positions.length; i < len; i++) {
				//转化为经纬度，并加入至临时数组
				var cartographic = Cesium.Cartographic.fromCartesian(polygon.positions[i]);
				var longitude = Cesium.Math.toDegrees(cartographic.longitude);
				var latitude = Cesium.Math.toDegrees(cartographic.latitude);
				positions.push([longitude, latitude]);
			}
			//去除重复点
			positions = unique(positions);
			var arr = [];
			//再次遍历转化为接口所需的数组格式
			for (var i = 0,
			len = positions.length; i < len; i++) {
				arr.push(positions[i][0]);
				arr.push(positions[i][1]);
			}
			//添加限高体对象
			skyline.addLimitbody({
				position: arr,
				name: "limitBody"
			});
		});
		handlerLimitBody.activate();
	}

	//通视分析 观察点
	function _chooseView() {
		//_clear();
		sightline = new Cesium.Sightline(scene);
		sightline.couldRemove = false;
		sightline.build();
		handlerViewPoint = new Cesium.PointHandler(viewer);
		
		handlerViewPoint.drawCompletedEvent.addEventListener(function(point) {
			var position = point.position._value;

			//将获取的点的位置转化成经纬度
			var cartographic = Cesium.Cartographic.fromCartesian(position);
			var longitude = Cesium.Math.toDegrees(cartographic.longitude);
			var latitude = Cesium.Math.toDegrees(cartographic.latitude);
			var height = cartographic.height;

			if (scene.viewFlag) {
				//设置视口位置
				sightline.viewPosition = [longitude, latitude, height];
				scene.viewFlag = false;
			} else {
				viewer.entities.remove(point);

				//添加视点
				sightline.addTargetPoint({
					position: [longitude, latitude, height],
					name: "point" + new Date()
				});
				sightline.couldRemove = true;
			}
		});
		scene.viewFlag = true;
		handlerViewPoint.activate();
	}

	//通视分析 目标点
	function _addViewPoint() {
		scene.viewFlag = false;
		handlerViewPoint.activate();
	}

	// 视域分析分析
	function _areaView() {
		//_clear();
		var viewPosition;
		//先将此标记置为true，不激活鼠标移动事件中对可视域分析对象的操作
		//先清除之前的可视域分析
		viewer.entities.removeAll();
		
		scene.viewFlag = true;
		pointHandler_areaView = new Cesium.PointHandler(viewer);
		//创建可视域分析对象
		viewshed3D = new Cesium.ViewShed3D(scene);
		var widget = viewer.cesiumWidget;
        if(Cesium.defined(viewshed3D.isDestroyed)) {
			viewshed3D = new Cesium.ViewShed3D(viewer.scene)
		}
		
		//激活绘制点类
		pointHandler_areaView.activate();         
		viewModel = {
			direction: 1.0,
			pitch: 1.0,
			distance: 1.0,
			verticalFov: 1.0,
			horizontalFov: 1.0,
			visibleAreaColor: '#ffffffff',
			invisibleAreaColor: '#ffffffff'
		};

		Cesium.knockout.track(viewModel);
		toolbar = document.getElementById('wrapper');
		Cesium.knockout.applyBindings(viewModel, toolbar);
      
		Cesium.knockout.getObservable(viewModel, 'direction').subscribe(function(newValue) {
			viewshed3D.direction = parseFloat(newValue);

		});
		Cesium.knockout.getObservable(viewModel, 'pitch').subscribe(function(newValue) {
			viewshed3D.pitch = parseFloat(newValue);
		});
		Cesium.knockout.getObservable(viewModel, 'distance').subscribe(function(newValue) {
			viewshed3D.distance = parseFloat(newValue);
		});
		Cesium.knockout.getObservable(viewModel, 'verticalFov').subscribe(function(newValue) {
			viewshed3D.verticalFov = parseFloat(newValue);

		});
		Cesium.knockout.getObservable(viewModel, 'horizontalFov').subscribe(function(newValue) {
			viewshed3D.horizontalFov = parseFloat(newValue);
		});
		Cesium.knockout.getObservable(viewModel, 'visibleAreaColor').subscribe(function(newValue) {
			var color = Cesium.Color.fromCssColorString(newValue);
			viewshed3D.visibleAreaColor = color;
		});
		Cesium.knockout.getObservable(viewModel, 'invisibleAreaColor').subscribe(function(newValue) {
			var color = Cesium.Color.fromCssColorString(newValue);
			viewshed3D.hiddenAreaColor = color;
		});
		handler = new Cesium.ScreenSpaceEventHandler(scene.canvas);
		//鼠标移动时间回调
		handler.setInputAction(function(e) {
			//若此标记为false，则激活对可视域分析对象的操作
			if (!scene.viewFlag) {
				//获取鼠标屏幕坐标,并将其转化成笛卡尔坐标
				var position = e.endPosition;
				var last = scene.pickPosition(position);
                
				//计算该点与视口位置点坐标的距离
				var distance = Cesium.Cartesian3.distance(viewPosition, last);
                console.log("shiyufenxi");
				if (distance > 0) {
					//将鼠标当前点坐标转化成经纬度
					var cartographic = Cesium.Cartographic.fromCartesian(last);
					var longitude = Cesium.Math.toDegrees(cartographic.longitude);
					var latitude = Cesium.Math.toDegrees(cartographic.latitude);
					var height = cartographic.height;

					//通过该点设置可视域分析对象的距离及方向
					viewshed3D.setDistDirByPoint([longitude, latitude, height]);
				}
			}
		},Cesium.ScreenSpaceEventType.MOUSE_MOVE);
       
		handler.setInputAction(function(e) {
			//鼠标右键事件回调，不再执行鼠标移动事件中对可视域的操作
			scene.viewFlag = true;
			viewModel.direction = viewshed3D.direction;
			viewModel.pitch = viewshed3D.pitch;
			viewModel.distance = viewshed3D.distance;
			viewModel.horizontalFov = viewshed3D.horizontalFov;
			viewModel.verticalFov = viewshed3D.verticalFov;

		},
		Cesium.ScreenSpaceEventType.RIGHT_CLICK);
		pointHandler_areaView.drawCompletedEvent.addEventListener(function(point) {
			var position = point.position._value;
			viewPosition = position;

			//将获取的点的位置转化成经纬度
			var cartographic = Cesium.Cartographic.fromCartesian(position);
			var longitude = Cesium.Math.toDegrees(cartographic.longitude);
			var latitude = Cesium.Math.toDegrees(cartographic.latitude);
			var height = cartographic.height;

			if (scene.viewFlag) {
				//设置视口位置
				viewshed3D.viewPosition = [longitude, latitude, height];
				viewshed3D.build();
				//将标记置为false以激活鼠标移动回调里面的设置可视域操作
				scene.viewFlag = false;
			}
		});

	}

	// 坡度和坡向
	function _podupoxiang() {
		slope = new Cesium.SlopeSetting();
		slope.DisplayMode = Cesium.SlopeSettingEnum.DisplayMode.FACE_AND_ARROW;
		slope.MaxVisibleValue = document.getElementById("widemax").value;
		slope.MinVisibleValue = document.getElementById("widemin").value;
		var colorTable = new Cesium.ColorTable();
		colorTable.insert(0, new Cesium.Color(255 / 255, 0 / 255, 0 / 255));
		colorTable.insert(20, new Cesium.Color(221 / 255, 224 / 255, 7 / 255));
		colorTable.insert(30, new Cesium.Color(20 / 255, 187 / 255, 18 / 255));
		colorTable.insert(50, new Cesium.Color(0, 161 / 255, 1));
		colorTable.insert(80, new Cesium.Color(9 / 255, 9 / 255, 255 / 255));

		wide = Cesium.HypsometricSettingEnum.AnalysisRegionMode.ARM_REGION;
		slope.ColorTable = colorTable;
		slope.Opacity = 0.5;

		//绘制多边形
		handlerPolygon = new Cesium.DrawHandler(viewer, Cesium.DrawMode.Polygon, 0);
		handlerPolygon.activeEvt.addEventListener(function(isActive) {
			if (isActive == true) {
				viewer.enableCursorStyle = false;
				viewer._element.style.cursor = '';
				$('body').removeClass('drawCur').addClass('drawCur');
			} else {
				viewer.enableCursorStyle = true;
				$('body').removeClass('drawCur');
			}
		});
		handlerPolygon.movingEvt.addEventListener(function(windowPosition) {
			if (windowPosition.x < 200 && windowPosition.y < 150) {
				// tooltip.setVisible(false);
				return;
			}
		});
		handlerPolygon.drawEvt.addEventListener(function(result) {
			if (!result.object.positions) {
				handlerPolygon.polygon.show = false;
				handlerPolygon.polyline.show = false;
				handlerPolygon.deactivate();
				handlerPolygon.activate();
				return;
			};
			var array = [].concat(result.object.positions);
			// tooltip.setVisible(false);
			var positions = [];
			for (var i = 0,
			len = array.length; i < len; i++) {
				var cartographic = Cesium.Cartographic.fromCartesian(array[i]);
				var longitude = Cesium.Math.toDegrees(cartographic.longitude);
				var latitude = Cesium.Math.toDegrees(cartographic.latitude);
				var h = cartographic.height;
				if (positions.indexOf(longitude) == -1 && positions.indexOf(latitude) == -1) {
					positions.push(longitude);
					positions.push(latitude);
					positions.push(h);
				}
			}

			slope.CoverageArea = positions;
			viewer.scene.globe.SlopeSetting = {
				slopeSetting: slope,
				analysisMode: wide
			};
			handlerPolygon.polygon.show = false;
			handlerPolygon.polyline.show = true;
			handlerPolygon.deactivate();
			handlerPolygon.activate();
		});

		viewer._cesiumWidget._creditContainer.style.display = "none";
		handlerPolygon.activate();

	}

	//拉伸分析
	function _controlHeight() {
		var viewModel = {
			extrudedHeight: 0
		};
		Cesium.knockout.track(viewModel);
		var setbar_polygon = document.getElementById('setbar_polygon');
		Cesium.knockout.applyBindings(viewModel, setbar_polygon);
		viewer.dataSources.add(Cesium.KmlDataSource.load(publicDir + '/data/controlHeight.kml', {
			camera: viewer.scene.camera,
			canvas: viewer.scene.canvas
		})).then(function(data) {
			viewer.zoomTo(data);
			var polygonEntity = data.entities.values[0];
			Cesium.knockout.getObservable(viewModel, 'extrudedHeight').subscribe(function(newValue) {
				polygonEntity.polygon['extrudedHeight'] = parseFloat(newValue);
			});
		});
	}


	/******************** 三维图层显隐开始 ********************/
	//图层管理
	function _layerManage(layer) {
		var classname;
		var thisname;
		var thisid;
		var childArry;
		var selected;
		var newid;
		var caseArry = ["方案1", "方案2"];
		var caseStr = "";
		var landArry = ["dem"];
		var landStr = "";
		
		//获取所有显示的图层 ---> html
		getLayer();
		
		//获取默认显示图层
		getShowLayer();
		
		//获取所有分层
		function getLayer() {
			$.ajax({
				type: "get",
				url: widgetLayerURL,
				dataType: "json",
				success: function(data) {
					if (data.status == true) {
						/*渲染普通图层*/
						//document.getElementById("layerTree").innerHTML = forTree(data["info"]);
						/* 废弃(只有单层)
						//给有子对象的元素加[+-]  
						$("#layerTree ul").each(function(index, element) {
							var ulContent = $(element).html();
							var spanContent = $(element).siblings("span").html();
							if (ulContent) {
								$(element).siblings("span").html("<i class='ace-icon fa fa-plus'></i> " + spanContent)
							} else {
								$(element).siblings("span").html("<i class='ace-icon fa fa-minus'></i> " + spanContent);
							}
						});
						*/
						//循环遍历数组id
						for (var i = 0; i < defaultShowArray.length; i++) {
							// 设置显示图层的选中状态
							$(".a" + defaultShowArray[i]).attr("checked", "checked");

						}
					}
				}
			});
		}

		//控制图层的显示隐藏
		$("#layerTree").on("click", "input",function() {
			// 获取点击的的图层的input的class名称
			classname = $(this).attr('class');
			// 获取点击的图层的input的图层名称
			thisname = $(this).next().html();
			// 截取字符串，获取id
			thisid = classname.substr(1, classname.length);
			// 获取当前图层包含的所有子节点
			childArry = $(this).parent().next().find("input[type='checkbox']");
			// 判断是否选中状态
			selected = $(this).is(':checked');
			// var idArry = new Array();
			if (childArry.length > 0) {
				for (var i = 0; i < childArry.length; i++) {
					var nodeChild = childArry[i];
					if (selected == true) {
						$(nodeChild).prop("checked", true);
						$(nodeChild).attr("checked", "checked");
					} else {
						$(nodeChild).prop("checked", false);
						$(nodeChild).removeAttr("checked");
					}
					newid = childArry[i].className.substr(1, classname.length);
					layerShowHide();
				}
			} else {
				newid = thisid;
				layerShowHide();
			}
		});


		// 控制真实图层显示隐藏接口调用
		function layerShowHide() {
			$.ajax({
				type: "post",
				url: widgetLayerURL,
				dataType: "json",
				data: "id=" + newid,
				success: function(data) {
					if (data.status == true) {
						var mapname = data['info'][0]['mapname'];
						//让选中的图层都显示
						for (var n = 0; n < layer.length; n++) {
							// console.log(layer[n]);
							var LayerIsThisResult = LayerIsThis(layer[n] , data['info'][0]);
							if (LayerIsThisResult[0] || layer[n]._name == thisname) {


								//图层开关设置 
								if (selected == true) { 
									//常规图层
									if(LayerIsThisResult[1]==1){
										layer[n].visible = true; 
									}
									//数字高程 DEM
									if(LayerIsThisResult[1]==2){
										viewer.terrainProvider = new Cesium.CesiumTerrainProvider({
										    url : flyGlobal.mapDemUrl,
										    isSct : true
										});
									}
									//遥感影像
									if(LayerIsThisResult[1]==3){
										//无功能
										layer[n].visible = true; 
									}
								} else { 
									//常规图层
									if(LayerIsThisResult[1]==1){
										layer[n].visible = false; 
									}
									//数字高程 DEM
									if(LayerIsThisResult[1]==2){
										viewer.terrainProvider = new Cesium.CesiumTerrainProvider({
										    url : flyGlobal.mapDemTmpUrl,
										    isSct : true
										});
									}
									//遥感影像
									if(LayerIsThisResult[1]==3){
										//无功能
										layer[n].visible = false; 
									}
								} 


							} 
						} 
					} 
				}, 
			}); 
		} 



		//匹配是否为当前图层
		var LayerIsThis = function(layer_i , mapname_i){
			if(layer_i._name){  //常规图层名称相同 则返回true
				if(layer_i._name == mapname_i['mapname']){
					return [true,1];
				}  
			}
			if(layer_i._url){  //数字高程
				if(layer_i._url.indexOf(mapname_i['mapname']) > 0){
					return [true,2];
				}  
			}
			if(layer_i._imageryProvider && layer_i._imageryProvider._name){  //遥感影像
				if( mapname_i['mapname'].indexOf(layer_i._imageryProvider._name) > 0 ){
					return [true,3];
				}
			}
			return [false,0];
		}


		//获取所有默认显示的图层 
		function getShowLayer() { 
			$.ajax({ 
				type: "post", 
				url: layerShow, 
				dataType: "json", 
				success: function(data) { 
					//先进行全部隐藏  无法隐藏(数字高程-遥感影像)
					for (var i = 0; i < layer.length; i++) { 
						//layer[i].visible = false; 
					} 
					if (data.status == true) { 
						//循环显示 
						var mapname = data.info;
						for (var i = 0; i < mapname.length; i++) {
							for (var n = 0; n < layer.length; n++) {
								var LayerIsThisResult = LayerIsThis(layer[n],mapname[i]);
								if (LayerIsThisResult[0]) { 
									layer[n].visible = true;
								}
							}
						}
					}
				}
			});
		}


		/*递归实现获取无级树数据并生成DOM结构*/
		var str = "";
		var defaultShowArray = new Array();
		var forTree = function(data) {
			for (var i = 0; i < data.length; i++) {
				var urlstr = "";
				try {
					if (data[i]["lists"] == false) {
						urlstr = "<div><span><input type='checkbox' class = 'a" + data[i]["id"] + "'> <a href='#'>" + data[i]["layername"] + "</a></span><ul style='display:block;'>";
					} else {
						urlstr = "<div><span><input type='checkbox' class = 'a" + data[i]["id"] + "'> <a href='#'>" + data[i]["layername"] + "</a></span><ul style='display:none;'>";
					}
					str += urlstr;
					if (data[i]["lists"] != false) {
						forTree(data[i]["lists"]);
					}
					str += "</ul></div>";
					if (data[i]["defaultshow"] == 1) {
						defaultShowArray.push(data[i]["id"]);
					}
				} catch(e) {}
			}
			return str;
		}

		/*
		 * 暂时无用
		 * 多级图层的展开关闭
		 *
		$("#layerTree").on("click", "span a",function() {
			var ul = $(this).parent().siblings("ul");
			$(this).parent().find("i").remove();
			var spanStr = $(this).parent().html();
			var spanContent = spanStr;
			var addStr = "";
			var that = $(this).parent();
			//program
			if (ul.css("display") == "none") {
				ul.show(300);
				that.html("");
				addStr = "<i class='ace-icon fa fa-minus'></i> " + spanContent;
				that.html(addStr);
			} else {
				ul.hide(300);
				that.html("");
				addStr = "<i class='ace-icon fa fa-plus'></i> " + spanContent;
				that.html(addStr);
			}
		});
		
		/* 
		 * 添加方案比选 
		 */
		for (var i = 0; i < caseArry.length; i++) {
			for (var n = 0; n < layer.length; n++) {
				//添加方案比选
				if (layer[n]._name && layer[n]._name == caseArry[i]) {
					caseStr = "<div><span><input type='checkbox'><a href='#'>" + caseArry[i] + "</a></span><ul>";
					$("#caseLayer").append(caseStr);
					layer[n].visible = false;
				}
			}
		}

		//方案比选显示隐藏点击事件
		$("#caseLayer").on("click", "input",function() {
			var thisname = $(this).next().html();
			selected = $(this).is(':checked');
			for (var n = 0; n < layer.length; n++) {
				if (layer[n]._name && layer[n]._name == thisname) {
					if (selected == true) layer[n].visible = true;
					else layer[n].visible = false;
				}
			}
		});

		/*
		 * 添加地形图层 - 废弃
		 *
		for (var i = 0; i < landArry.length; i++) {
			for (var n = 0; n < layer.length; n++) {
				//添加地形图层
				if (layer[n]._url) {
					var landurl = layer[n]._url;
					if (landurl.indexOf(landArry[i])) {
						landStr = "<div><span><input type='checkbox'><a href='#'>" + landArry[i] + "</a></span><ul>";
						$("#landLayer").append(landStr);
						layer[n].visible = false;
					}
				}
			}
		}

		/*
		 * 地形图层显示隐藏点击事件
		 */
		$("#landLayer").on("click", "input",function() {
			var thisname = $(this).next().html();
			selected = $(this).is(':checked');
			for (var n = 0; n < layer.length; n++) {
				if (layer[n]._url) {
					var landurl = layer[n]._url;
					if (landurl.indexOf(landArry[i])) {

						if (selected == true) {
							layer[n].visible = true;
							console.log(layer[n].visible);
							console.log(layer[n]);
						} else {
							layer[n].visible = false;
							console.log(layer[n].visible);
							console.log(layer[n]);
						}
					}
				}
			}
		});
	}
	/******************** 三维图层显隐结束 ********************/


	//OSGB添加
	function _OSGBaddSymbols(){
		if (handlerPolygon1) {
			// handlerPolygon1.polygon.show = false;
			handlerPolygon1.polyline.show = false;			
		}       
		handlerPolygon1 = new Cesium.DrawHandler(viewer,Cesium.DrawMode.Polygon,0);
        handlerPolygon1.activeEvt.addEventListener(function(isActive){
			if(isActive == true){
                viewer.enableCursorStyle = false;
                viewer._element.style.cursor = '';
                $('body').removeClass('drawCur').addClass('drawCur');
            }
            else{
                viewer.enableCursorStyle = true;
                $('body').removeClass('drawCur');
            }
        });
        handlerPolygon1.drawEvt.addEventListener(function(result){			
			var viewEnty = viewer.entities.add({
				name:"Green extruded polygon",
				polygon:{
					hierarchy:result.object.polygon.hierarchy,
					extrudedHeight:100.0,
					material:Cesium.Color.WHITE,
					closeTop:false,
					closeBottom:false
				}
			});
			
			$('.ContentextrudedHeight:last').val(100);
        	$('.ContentextrudedHeight:first').mouseup(function(){
        		result.object.polygon.extrudedHeight = this.value;
        		$('.ContentextrudedHeight:last').val(this.value);
        	});
			handlerPolygon1.deactivate();
			
        });
		handlerPolygon1  && handlerPolygon1.activate();
	}

	//OSGB压平 
	function _OSGBflat(){ 
		//var thislayer; 
		handlerPolygon2 = new Cesium.DrawHandler(viewer,Cesium.DrawMode.Polygon); 
        handlerPolygon2.activeEvt.addEventListener(function(isActive){ 
            if(isActive == true){ 
                viewer.enableCursorStyle = false;
                viewer._element.style.cursor = '';
                $('body').removeClass('drawCur').addClass('drawCur');
            }
            else{
                viewer.enableCursorStyle = true;
                $('body').removeClass('drawCur');
            }
        });
		handlerPolygon2.drawEvt.addEventListener(function(result){
            handlerPolygon2.polygon.show = false;
            handlerPolygon2.polyline.show = false;
            var polygon = result.object;
            var positions = polygon.positions;
            var flatPoints = [];
            for(var i = 0,j = positions.length;i < j;i++){
                var position = positions[i];
                var cartographic = Cesium.Cartographic.fromCartesian(position);
                var lon = Cesium.Math.toDegrees(cartographic.longitude);
                var lat = Cesium.Math.toDegrees(cartographic.latitude);
                var height = cartographic.height;
                flatPoints.push(lon);
                flatPoints.push(lat);
                flatPoints.push(height);
            }
            thislayer.addFlattenRegion({
                position : flatPoints,
                name : 'flatten' + Math.random()
            });
            handlerPolygon2.deactivate();
        });
        for(var i=0; i<layers.length; i++){
    		if(layers[i]._name && layers[i]._name == '倾斜摄影'){
    			$('#layerTree > div').eq(8).find('input').prop('checked','checked');
    			thislayer = layers[i];
    			thislayer.visible = true;
    		}
    	}
        handlerPolygon2 && handlerPolygon2.activate();
	}
	
	//OSGB-单值专题	
	function _OSGBextrude(){
		//和 添加 功能一致.
		// _OSGBaddSymbols();
		
	}




	


	//项目检索--翠屏街
    function _flyTo_qinfangyuan(){
		$("#flyControl").show();
		var routes = new Cesium.RouteCollection();
		var fpfUrl = publicDir + "/fly/cuipj.fpf";
		routes.fromFile(fpfUrl);
		flyManager = new Cesium.FlyManager({
			scene: scene,
			routes: routes
		});
		if (flyManager.readyPromise) {
			Cesium.when(flyManager.readyPromise,
			function() {
				flyManager.play();
			})
		}
	}
    //项目检索--青龙路
	function _flyTo_xiaoxue(){
		$("#flyControl").show();
		var routes = new Cesium.RouteCollection();
		var fpfUrl = publicDir + "/fly/qingll.fpf";
		routes.fromFile(fpfUrl);
		flyManager = new Cesium.FlyManager({
			scene: scene,
			routes: routes
		});
		if (flyManager.readyPromise) {
			Cesium.when(flyManager.readyPromise,
			function() {
				flyManager.play();
			})
		}
	}
    //项目检索--云翠街
	function _flyTo_xingyiyuan(){
		$("#flyControl").show();
		var routes = new Cesium.RouteCollection();
		var fpfUrl = publicDir + "/fly/yuncj.fpf";
		routes.fromFile(fpfUrl);
		flyManager = new Cesium.FlyManager({
			scene: scene,
			routes: routes
		});
		if (flyManager.readyPromise) {
			Cesium.when(flyManager.readyPromise,
			function() {
				flyManager.play();
			})
		}
	}


	$('#play').click(function(){
		flyManager && flyManager.play();
	});
	$('#pause').click(function(){
		flyManager && flyManager.pause();
	});
	$('#stop').click(function(){
		flyManager && flyManager.stop();
	});


	function _flyTo_searchBuild(){
		var searchName = $("#searchName").val();
		if(searchName == "翠屏街"){
			_flyTo_qinfangyuan();
		}else if(searchName == "青龙路"){
			_flyTo_xiaoxue();
		}else if(searchName == "云翠街"){
            _flyTo_xingyiyuan();
		}else{
            layer.msg('暂无内容！');
		}
	}


	//添加模型
    function _addModel(){
		$("#addModelSetting").show();
		var defaultUrl = publicDir + '/data/springTree.s3m';
		var viewModel = {
            heading : 1.0,
            pitch : 1.0,
            roll : 1.0,
            scale : 1.0,
            material : '#ffffff',
		};
		
		Cesium.knockout.track(viewModel);
        toolbar = document.getElementById('addModelSetting');
        Cesium.knockout.applyBindings(viewModel, toolbar);
        Cesium.knockout.getObservable(viewModel,'heading').subscribe(
                function(newValue) {
                    var rotationValue = Cesium.Math.toRadians(newValue);
                    if(viewer.selectedEntity){
                        var instance = viewer.selectedEntity.primitive;
                        var index = viewer.selectedEntity.index;
                        instance.updateRotation(new Cesium.HeadingPitchRoll(rotationValue,0,0),index);
                    }
                }
        );
        Cesium.knockout.getObservable(viewModel,'pitch').subscribe(
                function(newValue) {
                    var rotationValue = Cesium.Math.toRadians(newValue);
                    if(viewer.selectedEntity){
                        var instance = viewer.selectedEntity.primitive;
                        var index = viewer.selectedEntity.index;
                        instance.updateRotation(new Cesium.HeadingPitchRoll(0,rotationValue,0),index);
                    }
                }
        );
        Cesium.knockout.getObservable(viewModel,'roll').subscribe(
                function(newValue) {
                    var rotationValue = Cesium.Math.toRadians(newValue);
                    if(viewer.selectedEntity){
                        var instance = viewer.selectedEntity.primitive;
                        var index = viewer.selectedEntity.index;
                        instance.updateRotation(new Cesium.HeadingPitchRoll(0,0,rotationValue),index);
                    }
                }
        );
        Cesium.knockout.getObservable(viewModel,'scale').subscribe(
                function(newValue) {
                    var scale = parseFloat(newValue);
                    if(viewer.selectedEntity){
                        var instance = viewer.selectedEntity.primitive;
                        var index = viewer.selectedEntity.index;
                        instance.updateScale(new Cesium.Cartesian3(scale,scale,scale),index);
                    }
                }
        );
        Cesium.knockout.getObservable(viewModel,'material').subscribe(
                function(newValue) {
                    var color = Cesium.Color.fromCssColorString(newValue);
                    if(viewer.selectedEntity){
                        var instance = viewer.selectedEntity.primitive;
                        var index = viewer.selectedEntity.index;
                        instance.updateColor(color,index);
                    }
                }
        );
        Cesium.loadJson(publicDir + '/data/models.json').then(function(data){
            var result = data.s3mModels;
            for(var i = 0,j = result.length;i < j;i++){
                addItem(result[i]);
            }
        });
       
	    // var tooltip = createTooltip(document.body);
	    handlerPoint = new Cesium.DrawHandler(viewer,Cesium.DrawMode.Point);
		handlerPoint.activeEvt.addEventListener(function(isActive){
			if(isActive == true){
				viewer.enableCursorStyle = false;
				viewer._element.style.cursor = '';
				$('body').removeClass('drawCur').addClass('drawCur');
			}
			else{
				viewer.enableCursorStyle = true;
				$('body').removeClass('drawCur');
			}
		});

		handlerPoint.movingEvt.addEventListener(function(windowPosition){
			if(windowPosition.x < 210 && windowPosition.y < 120){
				// tooltip.setVisible(false);
				return ;
			}
			// tooltip.showAt(windowPosition,'<p>点击添加小品</p>');
		});

		var s3mInstanceColc = new Cesium.S3MInstanceCollection(scene._context);
		scene.primitives.add(s3mInstanceColc);
		handlerPoint.drawEvt.addEventListener(function(result){
			handlerPoint.clear();
			var point = result.object;
			var color =  Cesium.Color.WHITE;
			s3mInstanceColc.add(defaultUrl,{
				position : point.position,
				hpr : new Cesium.HeadingPitchRoll(0,0,0),
				scale : new Cesium.Cartesian3(1,1,1),
				color : color
			});
			var colorStr = color.toCssColorString();
			viewModel.material = colorStr;
			$('#colorPicker').css({
				color : colorStr
			});
				$("img").removeClass("selected");
			handlerPoint && handlerPoint.deactivate();
			// tooltip.setVisible(false);
		});


		$("#addModel").click(function() {
            if($(".level-one").hasClass("selected")){
                $(".level-one").removeClass("selected");
            }
            
            $("#addModel").addClass("selected");
            $("#addModelSetting").show();
            // handlerPolygon.deactivate();
        });

        $("#flatten").click(function(){
            if($(".level-one").hasClass("selected")){
                $(".level-one").removeClass("selected");
            }
            $("#addModelSetting").hide();
            $("#flatten").addClass("selected");
        })
        $(".close").click(function(){
            $("#addModelSetting").hide();
            $("#addModel").removeClass("selected");
        });
        $("#delete").click(function(){
            if(viewer.selectedEntity){
                var instance = viewer.selectedEntity.primitive;
				var index = viewer.selectedEntity.index;
                instance.updateScale(new Cesium.Cartesian3(0,0,0),index);
            }
		});
        
        $("#XPlus").click(function(){
            if(viewer.selectedEntity){
                var x = parseInt(document.getElementById("positionX").value);
                x++;
                document.getElementById("positionX").value=x;
                var instance = viewer.selectedEntity.primitive;
                var index = viewer.selectedEntity.index;
                var pos = instance._position;
                var newPos = new Cesium.Cartesian3(pos.x + 50,pos.y ,pos.z );
                instance.updatePosition(newPos,index);
            }
        });
        $("#XMinus").click(function(){
            if(viewer.selectedEntity){
                var x = parseInt(document.getElementById("positionX").value);
                x--;
                document.getElementById("positionX").value=x;
                var instance = viewer.selectedEntity.primitive;
                var index = viewer.selectedEntity.index;
                var pos = instance._position;
                var newPos = new Cesium.Cartesian3(pos.x - 50 ,pos.y ,pos.z );
                instance.updatePosition(newPos,index);
            }
        });
        $("#YPlus").click(function(){
            if(viewer.selectedEntity){
                var y = parseInt(document.getElementById("positionY").value);
                y++;
                document.getElementById("positionY").value = y;
                var instance = viewer.selectedEntity.primitive;
                var index = viewer.selectedEntity.index;
                var pos = instance._position;
                var newPos = new Cesium.Cartesian3(pos.x ,pos.y + 50,pos.z);
                instance.updatePosition(newPos,index);
            }
        });
        $("#YMinus").click(function(){
            if(viewer.selectedEntity){
                var y = parseInt(document.getElementById("positionY").value);
                y--;
                document.getElementById("positionY").value = y;
                var instance = viewer.selectedEntity.primitive;
                var index = viewer.selectedEntity.index;
                var pos = instance._position;
                var newPos = new Cesium.Cartesian3(pos.x ,pos.y - 50,pos.z );
                instance.updatePosition(newPos,index);
            }
        });
        $("#ZPlus").click(function(){
            if(viewer.selectedEntity){
                var z = parseInt(document.getElementById("positionZ").value);
                z++;
                document.getElementById("positionX").value = z;
                var instance = viewer.selectedEntity.primitive;
                var index = viewer.selectedEntity.index;
                var pos = instance._position;
                var newPos = new Cesium.Cartesian3(pos.x,pos.y,pos.z + 50);
                instance.updatePosition(newPos,index);
            }
        });
        $("#ZMinus").click(function(){
            if(viewer.selectedEntity){
                 var z = parseInt(document.getElementById("positionZ").value);
                z--;
                document.getElementById("positionX").value = z;
                var instance = viewer.selectedEntity.primitive;
                var index = viewer.selectedEntity.index;
                var pos = instance._position;
                var newPos = new Cesium.Cartesian3(pos.x ,pos.y ,pos.z - 50);
                instance.updatePosition(newPos,index);
            }
        });
        function addItem(data){
            var str = '<a><img style="width: 18%;height: 100%; margin-top:5px; margin-bottom:5px;" src={thumbnail} id={name}></a>'.replace('{thumbnail}',data.thumbnail).replace('{name}', data.name);
            var $el = $('#icons').append(str);
            var $child =$("#"+data.name);
            $child.on('click',function(){
                defaultUrl = data.path;             
                if($("img").hasClass("selected")){
                    $("img").removeClass("selected");
                    // handlerPolygon && handlerPolygon.deactivate();
                }
                else{
                    handlerPoint && handlerPoint.activate();
                    $(this).addClass("selected");
                }
            });
		}
		
		$('#loadingbar').remove();
      
	}
	//添加图片
	function _addImg(){
		$("#addImgSetting").show();

		$(".close").click(function(){
            $("#addImgSetting").hide();
            $("#addModel").removeClass("selected");
        });
	}

	//上传模型
	function _modelFileupload(){
		var uploading = false;
		$("#modelFileupload").on("change", function(){
			if(uploading){
				alert("文件正在上传中，请稍候");
				return false;
			}
			$.ajax({
				url: "../../../Upload/upload.php",
				type: 'POST',
				cache: false,
				data: new FormData($('#modelFileuploadForm')[0]),
				processData: false,
				contentType: false,
				dataType:"json",
				beforeSend: function(){
					uploading = true;
				},
				complete: function(data) {
					$("#modelFileuploadForm #tip").text("");
					$("#modelFileuploadForm #tip").text("文件上传成功");
					/*if (data.code == 1) {
						$("#logo").attr("src", data.msg);
					 } else {
					  showError(data.msg);
					}*/
					uploading = false;
				}
			});
		});

	}

	//上传图片
	function _modelPicUpload(){
		var uploading = false;

		$("#modelPicUpload").on("change", function(){
			if(uploading){
				alert("文件正在上传中，请稍候");
				return false;
			}
			$.ajax({
				url: "../../../Upload/upload.php",
				type: 'POST',
				cache: false,
				data: new FormData($('#modelPicUploadForm')[0]),
				processData: false,
				contentType: false,
				dataType:"json",
				beforeSend: function(){
					uploading = true;
				},
				complete: function(data) {
					$("#modelPicUploadForm #tip").text("");
					$("#modelPicUploadForm #tip").text("文件上传成功");
						/*if (data.code == 1) {
							$("#logo").attr("src", data.msg);
							} else {
							showError(data.msg);
							}*/
						uploading = false;
					}
			});
		});

	}

	
	//模型库加载
	function _modelKu(){
		//if ($("#build-item #build-content").text()!=''&& $("#lvhuan-item #lvhuan-content").text()!='' && $("#sheshi-item #sheshi-content").text()!='' && $("#whiteModel-item #whiteModel-content").text()!='') return;
		$.ajax({
			url: selectFileModelUrl,
			type: 'POST',
			cache: false,
			processData: false,
			contentType: false,
			dataType:"json",
			success: function(data) {
				debugger
				if(data.status){
					$("#build-item #build-content").empty();
					$("#lvhuan-item #lvhuan-content").empty();
					$("#sheshi-item #sheshi-content").empty();
					$("#whiteModel-item #whiteModel-content").empty();
					for(var k=0;k<data.info.length;k++){
						if($.trim(data.info[k].model_type)=="建筑"){
							$("#build-item #build-content").append('<div class="thumbnail"><img src=../../../'+data.info[k].modelSltSaveAllpath+'><div>');
						}
						if($.trim(data.info[k].model_type)=="绿化"){
							$("#lvhuan-item #lvhuan-content").append('<div class="thumbnail"><img src=../../../'+data.info[k].modelSltSaveAllpath+'><div>');
						}
						if($.trim(data.info[k].model_type)=="设施"){
							$("#sheshi-item #sheshi-content").append('<div class="thumbnail"><img src=../../../'+data.info[k].modelSltSaveAllpath+'><div>');
						}
						if($.trim(data.info[k].model_type)=="白模型"){
							$("#whiteModel-item #whiteModel-content").append('<div class="thumbnail"><img src=../../../'+data.info[k].modelSltSaveAllpath+'><div>');
						}
					}
				}else{
					if (typeof (data.error) != 'undefined'&& data.error != '') {
						alert(data.error);
					}
				}
			},
			error: function(data,status,e){
				alert(status);
			}
		});	
		
	}


	//模型管理
	function _modelManage(){
		if($('#modelManageSetting').css('display')=='none'){
			$('#modelManageSetting').show();
		}else{
			$('#modelManageSetting').hide();
		}
		$('#myTab a').click(function(e) {
            e.preventDefault(); //阻止a链接的跳转行为
            $(this).tab('show'); //显示当前选中的链接及关联的content
        });

        $("#modelManageSetting #table_modelList").empty();
        $("#modelManageSetting #table_modelList").append('<tr><th style="text-align:center">序号</th><th style="text-align:center">模型类型</th><th style="text-align:center">名称</th><th style="text-align:center">模型文件名称</th><th style="text-align:center">模型缩略图</th><th style="text-align:center">上传时间</th><th colspan="2" style="text-align:center">操作</th></tr>');
		
		//查询
		$.ajax({
			url: selectFileModelUrl,
			type: 'POST',
			cache: false,
			processData: false,
			contentType: false,
			dataType:"json",
			success: function(data) {
					if(data.status){
						var orderNo=0;
						for(var m=0;m<data.info.length;m++){
							orderNo++;
							$("#modelManageSetting #table_modelList").append('<tr class="success"><td>'+orderNo+'</td><td>'+data.info[m].model_type+'</td><td>'+data.info[m].modelname+'</td><td>'+data.info[m].modelFileName+'</td><td>'+data.info[m].modelSltName+'</td><td>'+data.info[m].addtimeshow+'</td><td><a href='+downFileModelUrl+data.info[m].id + ' id="download" class="layui-btn h35 mt2 layui-btn-normal">下载</a></td><td><button id="button_del" type="button" class="layui-btn h35 mt2 layui-btn-normal" onclick="_modelSltDelete(this,'+data.info[m].id+')">删除</button></td></tr>');
						}
					}else{
						if (typeof (data.error) != 'undefined'&& data.error != '') {
							alert(data.error);
						}
					}
			},
			error: function(data,status,e){
				alert(status);
			}
		});
	}

	//模型缩略图上传
	function _modelSltUpload(){

		$("#modelManageSetting #table_modelList").empty();
		$("#modelManageSetting #table_modelList").append('<tr><th style="text-align:center">序号</th><th style="text-align:center">模型类型</th><th style="text-align:center">名称</th><th style="text-align:center">模型文件名称</th><th style="text-align:center">模型缩略图</th><th style="text-align:center">上传时间</th><th colspan="2" style="text-align:center">操作</th></tr>');
		
		$.ajax({
			url: addFileModelUrl,
			type: 'POST',
			cache: false,
			data: new FormData($('#modelUploadForm')[0]),
			processData: false,
			contentType: false,
			dataType:"json",
			success: function(data) {
				if(data.status){
					var orderNo=0;
					for(var m=0;m<data.info.length;m++){
						orderNo++;
						$("#modelManageSetting #table_modelList").append('<tr class="success"><td>'+orderNo+'</td><td>'+data.info[m].model_type+'</td><td>'+data.info[m].modelname+'</td><td>'+data.info[m].modelFileName+'</td><td>'+data.info[m].modelSltName+'</td><td>'+data.info[m].addtimeshow+'</td><td><a href='+downFileModelUrl+data.info[m].id + ' id="download" class="layui-btn h35 mt2 layui-btn-normal">下载</a></td><td><button id="button_del" type="button" class="layui-btn h35 mt2 layui-btn-normal" onclick="_modelSltDelete(this,'+data.info[m].id+')">删除</button></td></tr>');
					}
					$("#modelUploadTab #tip").text("");
					$("#modelUploadTab #tip").text("上传成功");
				}else{
					if (typeof (data.error) != 'undefined'&& data.error != '') {
						alert(data.error);
					}
				}
			},
			error: function(data,status,e){
				alert(status);
			}
		});
	}


//工具栏--日照开关
function _sunOpen(){

	var mouseVal = $(".sunC").next().text();
	if(mouseVal=="日照打开"){
		viewer.shadows = true;
		shadowQuery = new Cesium.ShadowQueryPoints(scene);
		$.each(scene.layers._layerQueue,function(i, v) {
			v.shadowType = 2;
		});
		shadowQuery.build();
		$(".sunC").next().text("日照关闭");
	}
	else{
		viewer.shadows =  false;
		$(".sunC").next().text("日照打开");
	}
}

//工具栏--漫游选择
function _mouseSetting(){
	var mouseVal = $(".mouseC").next().text();
	if(mouseVal=="漫游"){
		viewer.enableCursorStyle = false;
		viewer._element.style.cursor = '';
		// $('body').attr("cursor","pointer");
		$('body').removeClass('mouseD').addClass('mouseP');
		$(".mouseC").next().text("箭头");
	}
	else{
		viewer.enableCursorStyle = false;
		viewer._element.style.cursor = '';
		$('body').removeClass('mouseP').addClass('mouseD');
		$(".mouseC").next().text("漫游");
	}
}
//等高线
function _sidebar() {
	//alert(111);
    //初始化viewer部件
    // var viewer = new Cesium.Viewer({
    // 	 //添加STK World Terrain地形服务
    //     terrainProvider : new Cesium.CesiumTerrainProvider({
    //         url : URL_CONFIG.STK,
    //         requestWaterMask : true,
    //         requestVertexNormals : true
    //     }),
    // });

    //创建分层设色对象
    var hyp = new Cesium.HypsometricSetting();
    //设置分层设色的显示模式为线
    hyp.DisplayMode = Cesium.HypsometricSettingEnum.DisplayMode.LINE;
    //设置线颜色为红色
    hyp._lineColor = new Cesium.Color(1.0, 0.0, 0.0, 1.0);
    //等高线间隔为100m
    hyp.LineInterval = 100.0;
    //设置分层设色的最大/最小可见高度
    hyp.MaxVisibleValue = 9000;
    hyp.MinVisibleValue = 0;
    //设置分层设色颜色表的最大/最小key值,表示在此高度范围内显示颜色表
    hyp.ColorTableMinKey = 2736.88110351563;
    hyp.ColorTableMaxKey = 5597.06640625;
    //新建颜色表
    var colorTable = new Cesium.ColorTable();

    colorTable.insert(5597.06640625,new Cesium.Color(0, 0, 255/255));
    colorTable.insert(5406.3873860677086,new Cesium.Color(0, 51/255, 255/255));
    colorTable.insert(5215.7083658854172,new Cesium.Color(0, 102/255, 255/255));
    colorTable.insert(5025.0293457031257,new Cesium.Color(0, 153/255, 255/255));
    colorTable.insert(4834.3503255208343,new Cesium.Color(0, 204/255, 255/255));
    colorTable.insert(4643.6713053385429,new Cesium.Color(0, 255/255, 255/255));
    colorTable.insert(4452.9922851562524,new Cesium.Color(51/255, 255/255, 204/255));
    colorTable.insert(4262.3132649739609,new Cesium.Color(102/255, 255/255, 153/255));
    colorTable.insert(4071.6342447916695,new Cesium.Color(153/255, 255/255, 102/255));
    colorTable.insert(3880.9552246093781,new Cesium.Color(204/255, 255/255, 51/255));
    colorTable.insert(3690.2762044270867,new Cesium.Color(255/255, 255/255, 0));
    colorTable.insert(3499.5971842447952,new Cesium.Color(255/255, 204/255, 0));
    colorTable.insert(3308.9181640625038,new Cesium.Color(255/255, 153/255, 0));
    colorTable.insert(3118.2391438802129,new Cesium.Color(255/255, 102/255, 0));
    colorTable.insert(2927.5601236979214,new Cesium.Color(255/255, 51/255, 0));
    colorTable.insert(2736.88110351563,new Cesium.Color(255/255, 0, 0));

    //设置分层设色的颜色表
    hyp.ColorTable = colorTable;
    //设置分层设色的透明度
    hyp.Opacity = 0.4;

    //下拉菜单变化时切换分层设色的显示模式
    $('#fillOptions').change(function(){
        var value = $(this).val();
        switch (value){
            case 'None' : viewer.scene.globe.HypsometricSetting = undefined;break;
            case 'Line' : {
                hyp.DisplayMode = Cesium.HypsometricSettingEnum.DisplayMode.LINE;
                viewer.scene.globe.HypsometricSetting = {
                    hypsometricSetting : hyp,
                    analysisMode : Cesium.HypsometricSettingEnum.AnalysisRegionMode.ARM_ALL
                };
            }
                break;
            case 'Region' : {
                hyp.DisplayMode = Cesium.HypsometricSettingEnum.DisplayMode.FACE;
                viewer.scene.globe.HypsometricSetting = {
                    hypsometricSetting : hyp,
                    analysisMode : Cesium.HypsometricSettingEnum.AnalysisRegionMode.ARM_ALL
                };
            }
                break;
            case 'Line_Region' : {
                hyp.DisplayMode = Cesium.HypsometricSettingEnum.DisplayMode.FACE_AND_LINE;
                viewer.scene.globe.HypsometricSetting = {
                    hypsometricSetting : hyp,
                    analysisMode : Cesium.HypsometricSettingEnum.AnalysisRegionMode.ARM_ALL
                };
            }
                break;
            default : break;
        }

    });
    $('#sidebar').show();
  //  $('#loadingbar').remove();
}	
//人视点双击
function _dbclickOpen(){	
	var mouseVal = $(".clickC").next().text();
	if(mouseVal=="人视点双击打开"){
		handler2 = new Cesium.ScreenSpaceEventHandler(scene.canvas);
		handler2.setInputAction(function(e) {		
			//获取点击位置笛卡尔坐标					
			var position = scene.pickPosition(e.position);
			//将笛卡尔坐标转化为经纬度坐标
			var cartographic = Cesium.Cartographic.fromCartesian(position);
			var longitude = Cesium.Math.toDegrees(cartographic.longitude);
			var latitude = Cesium.Math.toDegrees(cartographic.latitude);
			var height = cartographic.height;
			longitude = longitude + 0.001;
			latitude =  latitude + 0.0001
			scene.camera.setView({
				destination:new Cesium.Cartesian3.fromDegrees(longitude,latitude,height),
				orientation : {
					heading : 117.69,
					pitch : 50.300289
				} 
			});
		},
		Cesium.ScreenSpaceEventType.LEFT_DOUBLE_CLICK);
		$(".clickC").next().text("人视点双击关闭");
		$('body').removeClass('mouseD').addClass('mouseP');
	}
	else{
		handler2 && handler2.destroy();
		$(".clickC").next().text("人视点双击打开");
	}
}
	
	return {
		modelKu: _modelKu,
		modelSltUpload : _modelSltUpload,
		controlHeightAnalysis:_controlHeightAnalysis,
		clearControlHeightAnalysis:_clearControlHeightAnalysis,
		sevenLineAnalysis:_sevenLineAnalysis,
		clearSevenLineAnalysis:_clearSevenLineAnalysis,
		startSlopeAnalysis:_startSlopeAnalysis,
		clearSlopeAnalysis:_clearSlopeAnalysis,
		clearProfileAnalysis:_clearProfileAnalysis,
		profileAnalysis:_profileAnalysis,
		//floodAnalysis:_floodAnalysis,
		modelManage:_modelManage,
		sidebar:_sidebar,
		clearServiceRadius:_clearServiceRadius,
		serviceRadius:_serviceRadius,
		clearHORIZONTAL:_clearHORIZONTAL,
		HORIZONTAL:_HORIZONTAL,
		plotting: _plotting,
		modelPicUpload:_modelPicUpload,
		modelFileupload:_modelFileupload,
		autodivheight:_autodivheight,
		distance: _distance,
		area: _area,
		height: _height,
		digTerrain: _digTerrain,
		clear: _clear,
		huanshi: _huanshi,
		shadowAnalysis: _shadowAnalysis,
		shadowRadio: _shadowRadio,
		chooseSkyline: _chooseSkyline,
		setLimitBody: _setLimitBody,
		chooseView: _chooseView,
		addViewPoint: _addViewPoint,
		areaView: _areaView,
		podupoxiang: _podupoxiang,		
		controlHeight: _controlHeight,
		layerManage: _layerManage,
		flyTo_qinfangyuan:_flyTo_qinfangyuan,
		flyTo_xiaoxue:_flyTo_xiaoxue,
		flyTo_xingyiyuan:_flyTo_xingyiyuan,
		flyTo_searchBuild:_flyTo_searchBuild,
		OSGBaddSymbols : _OSGBaddSymbols,
		OSGBflat : _OSGBflat,
		OSGBextrude : _OSGBextrude,
		addModel:_addModel,
		addImg:_addImg,
		sunOpen:_sunOpen,
		mouseSetting:_mouseSetting,
		dbclickOpen:_dbclickOpen
	};
});
	